package com.shsoft.task;

import com.shsoft.MonitorApplication;
import com.shsoft.util.FileUtil;

import java.awt.image.BufferedImage;

public class ProcessingImageDataTask implements Runnable{

    private BufferedImage image;

    private int x;

    private int y;

    private boolean priorityData;

    public ProcessingImageDataTask(BufferedImage image, int x, int y, boolean priorityData) {
        this.image = image;
        this.x = x;
        this.y = y;
        this.priorityData = priorityData;
    }

    @Override
    public void run() {
        if(!MonitorApplication.passNormalData.get()){
            return;
        }
        if(MonitorApplication.serialport == null){
            return;
        }
        byte[] pixels = FileUtil.getRGB565ByteArray(image, x, y);
        if(priorityData){
            MonitorApplication.priorityDataArray.offer(pixels);
        }else {
            MonitorApplication.normalDataArray.offer(pixels);
        }
    }
}
